use Dosvid
go

if exists(select 1
		  from sysobjects
		  where name = 'Candidat_ExceptCommodityGroups')
  drop table Candidat_ExceptCommodityGroups
go

create table Candidat_ExceptCommodityGroups
(
  Id int identity(1,1) not null,
  CandidatID int not null,
  CommodityGroupId int not null
)  
go

alter table Candidat_ExceptCommodityGroups add constraint PK_Candidat_ExceptCommodityGroups_ID primary key(Id) 
go


alter table Candidat_ExceptCommodityGroups add constraint FK_Candidat_ExceptCommodityGroups_Candidates_CandidatID 
      foreign key (CandidatID) references Candidates(Id) on delete cascade
go


alter table Candidat_ExceptCommodityGroups add constraint FK_Candidat_ExceptCommodityGroups_CommodityGroups_CommodityGroupId 
      foreign key (CommodityGroupId) references CommodityGroups(Id) on delete cascade
go


create nonclustered index IX_Candidat_ExceptCommodityGroups_CandidatId on Candidat_ExceptCommodityGroups
       (CandidatID asc)
go
